package com.you.learning.springcloud.order.task;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Map;


@Component
@RabbitListener(queues = "springBootTopicQueue1") //监听的队列
@Slf4j
public class OrderTaskService {

    @RabbitHandler
    public void onMessage(Message message, Channel channel) {
        String consumerQueue = message.getMessageProperties().getConsumerQueue(); //消费的队列
        try {
            long deliveryTag = message.getMessageProperties().getDeliveryTag();
            //手工ack
            channel.basicAck(deliveryTag, true);
            log.info("receive--1: " + new String(message.getBody()));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

//    @RabbitHandler
//    public void process(byte[] msg) {
//        System.out.println("消费者收到消息  : " + new String(msg));
//    }

}

